<?php
session_start();
include_once '../Model/M_SubRubro.php';
$subrubro=new M_SubRubro();
$subrubro->setIdSubRubro($_REQUEST['idSubRubro']);
$subrubro->setIdRubro($_REQUEST['idRubro']);
$Objrubro = $subrubro->searchSubRubro();
if($Objrubro[0]['imagen'])
{
    unlink('../View/images/SubRubro/'.$Objrubro[0]['imagen']);
}

$subrubro->setNombre(strtoupper($_REQUEST['nom']));
$subrubro->setUsuModif($_SESSION['nombresCompletos']);
$imagen = $_FILES['rutaImagen']['name'];
$subrubro->setImagen($imagen);
$rpta=$subrubro->updateSubRubro();
if($rpta){
    $ruta = "../View/images/SubRubro/";
    copy($_FILES['rutaImagen']['tmp_name'], $ruta . $_FILES['rutaImagen']['name']);
    $_SESSION['color']='greenyellow';
    $_SESSION['mensaje']='Se Guardaron los Cambios';
    $_SESSION['pag']='SubRubro/V_SubRubro.php?idPag='.$_REQUEST['idPag'];
}else{
    $_SESSION['color']='red';
    $_SESSION['mensaje']='No se Pudo guardar los Cambios';
    $_SESSION['pag']='SubRubro/V_SubRubro.php?idSubRubro='.$_REQUEST['idSubRubro'].'&idPag='.$_REQUEST['idPag'];
}
?>
<script language="JavaScript" type="text/javascript">
    location.href='../View/Mensaje.php';
</script>
